package com.zbxx.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zbxx.domain.Department;
import com.zbxx.domain.PageBean;
import com.zbxx.service.DepartmentService;

import javax.annotation.Resource;

/*部门管理的action*/
public class DepartmentAction extends ActionSupport implements ModelDriven<Department> {
    //注入service
    @Resource
    private DepartmentService departmentService;
    //模型驱动使用的对象
    private Department department =new Department();
    @Override
    public Department getModel() {
        return department;
    }

    private Integer currPage=1;

    //提供一个查询的方法
    public String findAll(){
      PageBean<Department> pageBean= departmentService.findByPage(currPage);
      //将pageBean存入到值栈中
        ActionContext.getContext().getValueStack().push(pageBean);
        return "findAll";
    }

    //跳转到添加部门的页面的方法
    public String saveUI(){
        return "saveUI";
    }
    //添加部门执行的方法
    public String save(){
        departmentService.save(department);
        return "saveSuccess";
    }
    //编辑部门执行的方法
    public String edit(){
       department= departmentService.findById(department.getDid());
        return "editSuccess";
    }

    //修改部门的执行方法
    public String update(){
        departmentService.update(department);
        return "updateSuccess";
    }
    //删除部门的操作
    public String delete(){
       department= departmentService.findById(department.getDid());
       departmentService.delete(department);
        return "deleteSuccess";
    }

    public DepartmentService getDepartmentService() {
        return departmentService;
    }

    public void setDepartmentService(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Integer getCurrPage() {
        return currPage;
    }

    public void setCurrPage(Integer currPage) {
        this.currPage = currPage;
    }
}
